package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.util.utils.Sundry;
import com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyActivity.CollectionActivity;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.CollectionModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/30.
 */

public class CollectionActivityAdapter extends BaseAdapter {

    private Context mContext;

    List<CollectionModel> model= new ArrayList<>();
    public CollectionActivityAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem( List<CollectionModel> model){

        this.model=model;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_collection, null);
            holder.item_time = (TextView) convertView
                    .findViewById(R.id.item_time);
            holder.item_type = (TextView) convertView
                    .findViewById(R.id.item_type);

            holder.item_content = (TextView) convertView
                    .findViewById(R.id.item_content);
            holder.item_headings = (TextView) convertView
                    .findViewById(R.id.item_headings);
            holder.collect = (LinearLayout) convertView
                    .findViewById(R.id.collect);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final CollectionModel collectionModel = model.get(position);
        holder.item_type.setText(collectionModel.getClassname());
        holder.item_headings.setText(collectionModel.getCredit_title());
        holder.item_content.setText(collectionModel.getSubject());
        holder.item_time.setText(Sundry.getStrTime(1,collectionModel.getAddtime()));
        holder.collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((CollectionActivity)mContext).processcancel(collectionModel.getId());
            }
        });
        return convertView;
    }

    class ViewHolder {

        TextView item_time;

        TextView item_content;
        TextView item_headings;
        TextView item_type;
        LinearLayout collect;
    }
}


